package cn.iocoder.yudao.framework.server.websocket.security;

import org.springframework.util.StringUtils;

/**
 * 安全服务工具类
 *
 * @author 芋道源码
 */
public class SecurityFrameworkUtils {

    /**
     * HEADER 认证头 value 的前缀
     */
    public static final String AUTHORIZATION_BEARER = "Bearer";

    public final static String TOKEN_HEADER = "Authorization";

    public final static String SECURITY_CHECK_COMPLETE_ATTRIBUTE_KEY = "CHECK_COMPLETE";

    public final static String WEB_SOCKET_USER_ATTRIBUTE_KEY = "WEB_SOCKET_USER";

    private SecurityFrameworkUtils() {}

    public static String obtainAuthorization(String token) {
        if (!StringUtils.hasText(token)) {
            return null;
        }
        // 2. 去除 Token 中带的 Bearer
        int index = token.indexOf(AUTHORIZATION_BEARER + " ");
        return index >= 0 ? token.substring(index + 7).trim() : token;
    }

}
